package com.ggj2013.hbh.utils;

//import format.svg.SVGData;
import com.ggj2013.hbh.Visibility;
import nme.Assets;

class OcclusionParser {
	public static function parse (pathList:String, offsetX:Float = 0, offsetY:Float = 0 ) {
		pathList = "assets/occ/" + pathList + ".occ";
		var s:String= Assets.getText(pathList);
		var inPaths:Array<String> = s.split(":");
		var outSegs = [];
		for (inPath in inPaths) {
			var lastDims:Array<String> = [];
			var inNodes:Array<String> = inPath.split("\n");
			for (inNode in inNodes) {
				var inDims:Array<String> = inNode.split(",");
				if (inDims.length == 2) {
					if (lastDims.length > 0) {
						
						var dims1 = lastDims;
						var dims2 = inDims;
					
						var n:Visibility.Segment = { p1: 
		{ x:Std.parseFloat(dims1[0])*3.0+offsetX, y:Std.parseFloat(dims1[1])*3.0+offsetY, begin:false, segment:null, angle:0.0, visualize:false }, 
						  p2: 
		{ x:Std.parseFloat(dims2[0])*3.0+offsetX, y:Std.parseFloat(dims2[1])*3.0+offsetY, begin:false, segment:null, angle:0.0, visualize:false}, 
					      d:0.0 };
						outSegs.push(n);
					}
					lastDims = inDims;
				}
			}
		}
		return outSegs;
	}
}